package A1_贪心算法;

import java.util.Arrays;

public class LC_435无重叠区间 {
    public static void main(String[] args){
        int[][] intervals= {{1,2},{2,3},{3,4},{1,3}};
        int res=eraseOverlapIntervals(intervals);
        System.out.println(res);
    }
    public static int eraseOverlapIntervals(int[][] intervals) {
        if(intervals.length==0)
            return 0;
        Arrays.sort(intervals,(a,b)->Integer.compare(a[0],b[0]));
        int result=0;
        for(int i=1;i<intervals.length;i++){
            if(intervals[i][0]<intervals[i-1][1]){
                result++;
                intervals[i][1]=Math.min(intervals[i][1],intervals[i-1][1]);
            }
        }
        return result;
    }
}
